Popular Searches
Popular Course Categories
Popular Courses

Grid Architecture

Selenium Grid

Grid Architecture in Selenium

Selenium Grid Architecture is the structure used by Selenium Grid to distribute WebDriver test execution across different machines, browsers, operating systems, and environments. It allows automation tests to send browser commands to remote machines instead of running every test only on the local computer.

Selenium Grid is especially useful for parallel testing, cross-browser testing, cross-platform testing, distributed execution, and scalable automation frameworks. In Selenium Grid 4, the architecture is built from several components such as Router, Distributor, New Session Queue, Session Map, Event Bus, and Node.

In a typical Grid execution, the test sends a new WebDriver session request to the Grid. The Router receives the request, the Distributor identifies a suitable Node and slot, and the Node creates the browser session. After the session is created, subsequent WebDriver commands are routed to the Node where the session is running.

Course Resource: Selenium Training | Register for Course Demo


1. What is Selenium Grid?

Selenium Grid is a Selenium component that allows WebDriver tests to execute on remote machines. Instead of running every browser session on one computer, Grid can distribute sessions across multiple machines and browser environments.

For example, an organization may have the following testing requirements:

  • Chrome on Windows.
  • Firefox on Windows.
  • Edge on Windows.
  • Chrome on Linux.
  • Firefox on Linux.
  • Different browser versions.
  • Multiple test executions at the same time.

Without Grid, these tests may need to run sequentially or require separate local environments. Grid provides a centralized mechanism for distributing WebDriver sessions.


2. Why is Grid Architecture Important?

Understanding Grid architecture is important because Selenium Grid is not simply a single server. Modern Selenium Grid consists of multiple logical components that cooperate to receive requests, queue sessions, find available execution slots, maintain session information, and communicate with browser machines.

  • Supports parallel test execution.
  • Supports remote browser execution.
  • Supports cross-browser testing.
  • Supports cross-platform testing.
  • Allows browser sessions to run on different machines.
  • Improves scalability of large automation suites.
  • Provides centralized routing of WebDriver requests.
  • Allows different Grid components to be deployed separately in distributed architectures.


3. Basic Grid Architecture

A simplified Selenium Grid architecture can be represented as follows:

Test Automation Code

        |

        v

RemoteWebDriver

        |

        v

     Router

        |

        v

New Session Queue

        |

        v

   Distributor

        |

        v

   Available Slot

        |

        v

      Node

        |

        v

Browser Instance

Additional components such as the Session Map and Event Bus help the Grid maintain session information and communication between Grid components.


4. Major Components of Selenium Grid

The major components of the Selenium Grid architecture are:

ComponentPrimary Responsibility
RouterActs as the main entry point and routes incoming WebDriver requests.
New Session QueueStores new session requests waiting to be assigned.
DistributorFinds a suitable Node and slot for a new session.
NodeRuns the actual WebDriver browser sessions.
Session MapMaps session IDs to the Nodes running those sessions.
Event BusProvides asynchronous communication between Grid components.


5. Router

The Router acts as the front-facing component of Selenium Grid. It receives incoming WebDriver requests and determines where those requests should be sent.

For a new session request, the Router directs the request toward the session-creation flow. For commands belonging to an existing session, it uses session information to route the request toward the appropriate Node.

Client

  |

  v

Router

  |

  +---- New Session Request ----> Session Queue

  |

  +---- Existing Session ------> Correct Node

The Router therefore provides a single entry point for clients communicating with a Grid.


6. New Session Queue

The New Session Queue maintains incoming requests for new WebDriver sessions that have not yet been assigned to a Node.

When many tests start at the same time, there may not be an immediately available slot for every requested session. The queue allows those requests to wait until the Distributor can assign them to appropriate slots.

Test 1 ----\

Test 2 -----\

Test 3 ------> New Session Queue

Test 4 -----/

Test 5 ----/

The queue is particularly useful when a Grid is processing many concurrent test requests.


7. Distributor

The Distributor is responsible for deciding where a new session should run. It maintains information about available Nodes and their slots and attempts to match incoming session capabilities with suitable slots.

For example, if a test requests Chrome, the Distributor looks for a Node containing a compatible Chrome slot.

New Session Request

        |

        v

   Distributor

        |

        +---- Chrome Slot ----> Node A

        |

        +---- Firefox Slot ---> Node B

        |

        +---- Edge Slot ------> Node C


8. Node

A Node is the machine or execution endpoint where WebDriver sessions actually run. A Node can provide one or more browser execution slots.

A Node may be configured to support browsers such as:

  • Google Chrome.
  • Mozilla Firefox.
  • Microsoft Edge.
  • Other supported WebDriver-compatible browser environments.

Example:

Node 1

|

+-- Chrome Slot

+-- Chrome Slot

+-- Firefox Slot

 

Node 2

|

+-- Edge Slot

+-- Firefox Slot

+-- Chrome Slot

The Distributor selects an appropriate available slot based on the requested capabilities.


9. What is a Slot?

A slot represents a place where a WebDriver session can run. A Node can have one or more slots.

For example:

Node

|

+-- Slot 1 - Chrome

+-- Slot 2 - Chrome

+-- Slot 3 - Firefox

+-- Slot 4 - Edge

If four compatible sessions can run concurrently, the Node can provide four available execution slots, subject to its configuration and resources.


10. Session Map

The Session Map maintains a mapping between a WebDriver session ID and the Node where that session is running.

For example:

Session IDNode
session-001Node-1
session-002Node-2
session-003Node-1

When a WebDriver command arrives for an existing session, the Grid can determine the Node responsible for that session.


11. Event Bus

The Event Bus provides asynchronous communication between Grid components. Components can publish events and other components can listen for those events.

For example, Node registration and status-related communication can use the Event Bus as part of the Grid's internal communication architecture.

Node

 |

 | Event

 v

Event Bus

 |

 +--------> Distributor

 |

 +--------> Other Grid Components

The Event Bus helps reduce direct coupling between components that need to communicate asynchronously.


12. Complete Selenium Grid 4 Architecture

                    Test Client

                         |

                         v

                  RemoteWebDriver

                         |

                         v

                      Router

                    /       \

                   /         \

                  v           v

       New Session Queue   Session Map

                  |

                  v

             Distributor

                  |

        +---------+---------+

        |         |         |

        v         v         v

      Node 1    Node 2    Node 3

        |         |         |

     Chrome     Firefox    Edge

     Firefox    Chrome     Chrome

        |         |         |

        +---------+---------+

                  |

                  v

             Browser Sessions

 

              Event Bus

                  |

        Internal Component

        Communication


13. How Grid Handles a New Session

When a Selenium test requests a new browser session, the request passes through several Grid components.

  1. The Selenium test creates a RemoteWebDriver request.
  2. The request reaches the Grid Router.
  3. The Router identifies it as a new session request.
  4. The request is placed into the New Session Queue.
  5. The Distributor receives the pending request.
  6. The Distributor examines available Nodes and slots.
  7. The requested capabilities are matched against available slots.
  8. A suitable Node is selected.
  9. The Node creates the browser session.
  10. The session information is associated with the session ID.
  11. Subsequent commands are routed to the Node running the session.


14. New Session Execution Flow

Test Starts

    |

    v

RemoteWebDriver

    |

    v

Router

    |

    v

New Session Queue

    |

    v

Distributor

    |

    v

Capability Matching

    |

    v

Available Slot

    |

    v

Node

    |

    v

Browser

    |

    v

WebDriver Session Created


15. Existing Session Request Flow

Once a session has been created, WebDriver commands are associated with the session ID.

Test

 |

 v

Router

 |

 v

Session ID

 |

 v

Session Map

 |

 v

Correct Node

 |

 v

Browser Session

 |

 v

WebDriver Command Executed

This allows commands such as click, sendKeys, navigation, JavaScript execution, and element interaction to reach the browser session that belongs to the test.


16. Browser Capability Matching

Grid needs to determine whether a Node can satisfy the capabilities requested by the test.

For example, a test may request:

Chrome

Windows

Specific Browser Configuration

The Distributor checks available slots and looks for a compatible configuration.

Requested CapabilityAvailable SlotPossible Match
ChromeChromeYes
FirefoxChromeNo
EdgeEdgeYes


17. BrowserName Capability

The browserName capability can be used to identify the requested browser.

ChromeOptions options = new ChromeOptions();

 

WebDriver driver =

    new RemoteWebDriver(

        new URL("http://localhost:4444"),

        options

    );

The requested capabilities are evaluated against the capabilities available on Grid Nodes.


18. RemoteWebDriver and Grid

RemoteWebDriver is commonly used when the browser is running remotely through Selenium Grid.

WebDriver driver = new RemoteWebDriver(

    new URL("http://localhost:4444"),

    new ChromeOptions()

);

In this model, the Java test code and browser execution environment do not have to be located on the same machine.


19. Local WebDriver vs RemoteWebDriver

FeatureLocal WebDriverRemoteWebDriver
Browser LocationUsually local machineRemote/Grid machine
Grid RequiredNoTypically when using Grid
Parallel ScalingLimited by local resourcesCan scale across Nodes
Cross-Machine ExecutionNot the primary modelYes
Typical UseLocal developmentDistributed/remote automation


20. Selenium Grid Modes

Selenium Grid can be operated in different configurations depending on the requirements of the automation environment.

Standalone Mode

Standalone mode provides a simple Grid setup in which the required Grid functionality runs through a single server process.

Test

 |

 v

Standalone Grid

 |

 v

Browser

Hub-Node Mode

Hub-Node mode provides a central Hub with one or more Nodes. The Hub provides the central Grid endpoint while Nodes provide browser execution capacity.

             Hub

              |

      +-------+-------+

      |       |       |

    Node 1  Node 2  Node 3

      |       |       |

   Chrome   Firefox   Edge

Fully Distributed Mode

In a fully distributed architecture, the Grid components can be started separately and communicate over the network.

Router

  |

  +---- Session Queue

  |

  +---- Distributor

  |

  +---- Session Map

  |

  +---- Event Bus

  |

  +---- Nodes


21. Standalone Architecture

Standalone mode is useful for simpler Grid environments where separate deployment of individual components is unnecessary.

Test Client

    |

    v

Standalone Server

    |

    v

Browser

It provides a simple entry point while still allowing remote WebDriver execution.


22. Hub and Node Architecture

In Hub-Node architecture, the Hub acts as the central coordination point and Nodes provide browser execution environments.

                    Hub

                     |

       +-------------+-------------+

       |             |             |

       v             v             v

    Node 1        Node 2        Node 3

     Chrome        Firefox        Edge

     Windows       Linux          Windows

This architecture is useful when different machines provide different browser or operating-system combinations.


23. Fully Distributed Architecture

Fully distributed Grid architecture separates the major Grid components. This architecture can be useful for larger or more complex environments where individual components need independent deployment and scaling.

                         Router

                           |

             +-------------+-------------+

             |             |             |

             v             v             v

       Session Queue   Session Map   Distributor

             |                           |

             |                           v

             |                         Nodes

             |                    +------+------+ 

             |                    |      |      |

             |                  Node1  Node2  Node3

             |

             +---------- Event Bus ----------+

                           |

                    Grid Components


24. Grid Architecture Communication

Selenium Grid uses both synchronous and asynchronous communication mechanisms.

Synchronous Communication

Synchronous communication is useful when a component needs a response to a request, such as WebDriver commands and other request-response operations.

Asynchronous Communication

Asynchronous communication is useful when information needs to be published as an event and the sender does not need to wait for an immediate response.


25. Node Registration

When a Node joins the Grid, it provides information about its status, capabilities, and available slots. The Distributor uses this information to maintain its model of the available Grid resources.

Node Starts

    |

    v

Node Announces Status

    |

    v

Distributor Detects Node

    |

    v

Node Status Checked

    |

    v

Capabilities / Slots Registered

    |

    v

Node Available for Sessions


26. Node Health and Status

The Grid maintains information about Nodes so that session requests can be assigned appropriately.

Important Node concepts include:

  • Availability.
  • Node identity.
  • Operating-system information.
  • Browser capabilities.
  • Available slots.
  • Maximum session capacity.
  • Current sessions.
  • Node URL.


27. Node Slots and Parallel Execution

A Node can provide multiple slots depending on its configuration and available resources.

Node 1

|

+-- Slot 1 - Chrome

+-- Slot 2 - Chrome

+-- Slot 3 - Firefox

+-- Slot 4 - Edge

 

Parallel Sessions

|

+-- Test A - Slot 1

+-- Test B - Slot 2

+-- Test C - Slot 3

+-- Test D - Slot 4

The exact concurrency that should be configured depends on the machine's CPU, memory, browser workload, and test characteristics.


28. Parallel Test Execution Using Grid

One of the primary reasons for using Grid is to execute independent tests concurrently.

Test Suite

    |

    +---- Test 1 ----> Node 1

    |

    +---- Test 2 ----> Node 2

    |

    +---- Test 3 ----> Node 3

    |

    +---- Test 4 ----> Node 1

Instead of waiting for every test to complete sequentially, multiple sessions can execute at the same time when sufficient Grid capacity is available.


29. Cross-Browser Testing

Selenium Grid can be used to test the same application against multiple browsers.

TestBrowserNode
Login TestChromeNode 1
Login TestFirefoxNode 2
Login TestEdgeNode 3

This helps teams validate browser compatibility without maintaining all browser environments on one developer machine.


30. Cross-Platform Testing

Grid can also distribute tests across different operating systems.

                 Selenium Grid

                       |

       +---------------+---------------+

       |               |               |

       v               v               v

 Windows Node      Linux Node       Other Node

 Chrome            Firefox          Browser

 Edge              Chrome           Configuration

This is useful when an application needs to be validated across multiple operating-system and browser combinations.


31. Grid URL

The Grid URL is the endpoint used by the test client to communicate with the Grid. In common Selenium Grid configurations, the default endpoint is based on port 4444.

http://localhost:4444

In a remote environment, the URL can point to the address of the Grid Router or the relevant Grid entry point.


32. RemoteWebDriver Example with Chrome

import java.net.URL;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeOptions;

import org.openqa.selenium.remote.RemoteWebDriver;

 

public class GridTest {

 

    public static void main(String[] args) throws Exception {

 

        ChromeOptions options = new ChromeOptions();

 

        WebDriver driver = new RemoteWebDriver(

            new URL("http://localhost:4444"),

            options

        );

 

        driver.get("https://example.com");

 

        System.out.println(driver.getTitle());

 

        driver.quit();

    }

}

Here, the test creates a RemoteWebDriver session using the Grid endpoint rather than directly creating a local ChromeDriver session.


33. RemoteWebDriver with Firefox

import java.net.URL;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxOptions;

import org.openqa.selenium.remote.RemoteWebDriver;

 

public class FirefoxGridTest {

 

    public static void main(String[] args) throws Exception {

 

        FirefoxOptions options = new FirefoxOptions();

 

        WebDriver driver = new RemoteWebDriver(

            new URL("http://localhost:4444"),

            options

        );

 

        driver.get("https://example.com");

 

        System.out.println(driver.getTitle());

 

        driver.quit();

    }

}


34. RemoteWebDriver with Edge

import java.net.URL;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.edge.EdgeOptions;

import org.openqa.selenium.remote.RemoteWebDriver;

 

public class EdgeGridTest {

 

    public static void main(String[] args) throws Exception {

 

        EdgeOptions options = new EdgeOptions();

 

        WebDriver driver = new RemoteWebDriver(

            new URL("http://localhost:4444"),

            options

        );

 

        driver.get("https://example.com");

 

        System.out.println(driver.getTitle());

 

        driver.quit();

    }

}


35. Grid Test Execution Flow

1. Test starts

       |

       v

2. RemoteWebDriver created

       |

       v

3. Request reaches Router

       |

       v

4. New Session Queue

       |

       v

5. Distributor receives request

       |

       v

6. Capabilities are matched

       |

       v

7. Suitable Node selected

       |

       v

8. Slot allocated

       |

       v

9. Browser session created

       |

       v

10. WebDriver commands execute

       |

       v

11. Test finishes

       |

       v

12. Session is terminated


36. Grid Architecture with TestNG

Selenium Grid is frequently combined with TestNG for parallel browser automation.

TestNG

  |

  +---- Test 1

  |

  +---- Test 2

  |

  +---- Test 3

  |

  v

RemoteWebDriver

  |

  v

Selenium Grid

  |

  +---- Chrome Node

  +---- Firefox Node

  +---- Edge Node

TestNG controls test execution while Selenium Grid provides remote browser execution infrastructure.


37. Grid Architecture with DataProvider

A TestNG Data Provider can be used to supply browser or test-data combinations while Grid provides the execution environment.

@DataProvider(name = "browsers")

public Object[][] browsers() {

    return new Object[][] {

        {"chrome"},

        {"firefox"},

        {"edge"}

    };

}

 

@Test(dataProvider = "browsers")

public void browserTest(String browser) {

    // Create the appropriate browser options

    // and start a RemoteWebDriver session.

}

This allows one logical test method to execute with different browser configurations.


38. Grid Architecture with Page Object Model

Grid can be combined with the Page Object Model to separate test logic, page interaction logic, and browser infrastructure.

Test Class

    |

    v

Page Object

    |

    v

WebDriver

    |

    v

RemoteWebDriver

    |

    v

Selenium Grid

    |

    v

Node

    |

    v

Browser


39. Grid with a WebDriver Factory

Large automation frameworks commonly use a Driver Factory to centralize WebDriver creation.

DriverFactory

      |

      +---- Local Chrome

      |

      +---- Local Firefox

      |

      +---- Remote Chrome

      |

      +---- Remote Firefox

      |

      +---- Remote Edge

      |

      v

WebDriver Instance

A factory can hide browser creation details from individual test classes and make the framework easier to maintain.


40. Example Driver Factory Concept

public class DriverFactory {

 

    public static WebDriver createRemoteChrome() throws Exception {

 

        ChromeOptions options = new ChromeOptions();

 

        return new RemoteWebDriver(

            new URL("http://localhost:4444"),

            options

        );

    }

}

The exact factory design can be extended to support multiple browsers, environments, and execution modes.


41. Grid Architecture for CI/CD

Selenium Grid can be integrated with CI/CD systems so that automated tests run against a remote browser infrastructure during pipeline execution.

Developer

   |

   v

Git Repository

   |

   v

CI/CD Pipeline

   |

   v

Build

   |

   v

TestNG / JUnit / PyTest

   |

   v

RemoteWebDriver

   |

   v

Selenium Grid

   |

   +---- Node 1

   +---- Node 2

   +---- Node 3

   |

   v

Test Results

   |

   v

Reports


42. Grid Architecture with Jenkins

A Jenkins pipeline can trigger Selenium tests that connect to a remote Grid.

Jenkins

   |

   v

Maven / Test Runner

   |

   v

Automation Tests

   |

   v

RemoteWebDriver

   |

   v

Selenium Grid

   |

   v

Browser Nodes

This architecture allows centralized automated execution without requiring every CI worker to contain every browser environment locally.


43. Grid Status

Selenium Grid provides a status endpoint that can be used to inspect the state of the Grid.

GET http://localhost:4444/status

The status information can include information about registered Nodes, sessions, and slots.


44. Monitoring Nodes

Monitoring Grid Nodes is important in distributed automation environments. Teams should monitor:

  • Node availability.
  • Number of active sessions.
  • Available slots.
  • CPU usage.
  • Memory usage.
  • Browser failures.
  • Session creation failures.
  • Network connectivity.


45. Graceful Node Drain

A Node may need to be removed from new session scheduling while allowing existing sessions to complete. This is known as draining the Node.

Node Active

    |

    v

Drain Requested

    |

    v

No New Sessions

    |

    v

Existing Sessions Complete

    |

    v

Node Can Shut Down / Restart

This approach is useful during maintenance or controlled infrastructure changes.


46. Grid Scalability

One of the major benefits of Grid architecture is that browser execution capacity can be increased by adding more Nodes.

Small Grid

 

        Router

          |

       Node 1

 

 

Expanded Grid

 

        Router

          |

    +-----+-----+-----+

    |     |     |     |

 Node 1 Node 2 Node 3 Node 4

    |     |     |     |

 Chrome Firefox Edge Chrome

Adding Nodes can increase the number of available browser execution slots, subject to infrastructure capacity and Grid configuration.


47. Grid Architecture for Large Automation Frameworks

                    Test Framework

                          |

                +---------+---------+

                |                   |

             TestNG             DataProvider

                |                   |

                +---------+---------+

                          |

                    Driver Factory

                          |

                    RemoteWebDriver

                          |

                       Router

                          |

          +---------------+---------------+

          |               |               |

     Distributor     Session Map     Session Queue

          |

       Event Bus

          |

    +-----+-----+-----+

    |     |     |     |

   Node  Node  Node  Node

    |     |     |     |

 Chrome Firefox Edge Chrome

    |

    v

Application


48. Advantages of Selenium Grid Architecture

  • Parallel Execution: Multiple browser sessions can run concurrently.
  • Cross-Browser Testing: Tests can be executed against different browsers.
  • Cross-Platform Testing: Different operating-system environments can be used.
  • Remote Execution: Browsers can run on machines separate from the test client.
  • Scalability: Additional Nodes can provide additional execution capacity.
  • Centralized Access: Tests can communicate through a common Grid entry point.
  • CI/CD Integration: Grid can be integrated into automated build and testing pipelines.
  • Resource Distribution: Browser sessions can be distributed across available execution environments.


49. Limitations and Challenges

  • Grid infrastructure requires additional setup and maintenance.
  • Network failures can affect remote sessions.
  • Browser and driver compatibility must be managed.
  • Parallel execution requires careful test isolation.
  • Shared WebDriver instances can cause concurrency problems.
  • Grid capacity should be matched to available machine resources.
  • Distributed deployments require proper network configuration.
  • Debugging remote failures can be more complex than debugging local tests.
  • Security should be considered when exposing Grid endpoints.


50. Common Mistakes in Grid Architecture

  • Using a local WebDriver when remote execution is required.
  • Using an incorrect Grid URL.
  • Starting a Node without the required browser environment.
  • Using unsupported or mismatched browser capabilities.
  • Sharing one WebDriver instance between parallel tests.
  • Ignoring Node resource limitations.
  • Running too many concurrent browser sessions on a small machine.
  • Not monitoring failed or unavailable Nodes.
  • Exposing the Grid endpoint unnecessarily to untrusted networks.
  • Not separating test data and browser infrastructure.


51. Best Practices for Selenium Grid

  • Use independent WebDriver instances for independent test sessions.
  • Keep tests thread-safe when executing in parallel.
  • Use a Driver Factory for centralized WebDriver creation.
  • Use Page Object Model for application interaction logic.
  • Use meaningful browser and environment configuration.
  • Monitor Node availability and resource usage.
  • Keep browser and driver versions compatible.
  • Use CI/CD integration for repeatable execution.
  • Secure Grid endpoints and network access.
  • Use appropriate session limits based on machine capacity.
  • Use Node draining for controlled maintenance.
  • Collect logs and reports to troubleshoot remote failures.


52. Grid Architecture vs Traditional Local Execution

FeatureLocal ExecutionGrid Execution
Execution LocationLocal machineRemote/Distributed machines
Parallel CapacityLimited by local resourcesCan use multiple Nodes
Cross-BrowserRequires local browsersCan distribute across Nodes
Cross-PlatformLimited to available local OSCan use different OS environments
InfrastructureSimpleMore components
ScalabilityLimitedCan add Nodes
Remote ExecutionNoYes


53. Grid Architecture vs Hub-Node Architecture

ConceptHub-NodeFully Distributed Grid
Central HubYesNo single monolithic Hub is required
RouterPart of Hub functionalitySeparate component
DistributorPart of Hub functionalitySeparate component
Session MapPart of Hub functionalitySeparate component
Session QueuePart of Hub functionalitySeparate component
Event BusPart of Hub functionalitySeparate component
DeploymentSimplerMore distributed


54. Practical Project Structure

selenium-grid-project

|

|-- src

|   |-- test

|       |-- java

|           |-- tests

|           |   |-- LoginTest.java

|           |   |-- SearchTest.java

|           |   |-- CheckoutTest.java

|           |

|           |-- pages

|           |   |-- LoginPage.java

|           |   |-- SearchPage.java

|           |   |-- CheckoutPage.java

|           |

|           |-- utilities

|               |-- DriverFactory.java

|               |-- ConfigReader.java

|               |-- WaitUtility.java

|

|-- pom.xml

|-- testng.xml


55. Practical Grid Test Example

import java.net.URL;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeOptions;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

 

public class GridTest {

 

    private WebDriver driver;

 

    @BeforeMethod

    public void setup() throws Exception {

 

        ChromeOptions options = new ChromeOptions();

 

        driver = new RemoteWebDriver(

            new URL("http://localhost:4444"),

            options

        );

 

        driver.manage().window().maximize();

    }

 

    @Test

    public void verifyPageTitle() {

 

        driver.get("https://example.com");

 

        String title = driver.getTitle();

 

        Assert.assertNotNull(title);

        System.out.println("Title: " + title);

    }

 

    @AfterMethod

    public void tearDown() {

 

        if (driver != null) {

            driver.quit();

        }

    }

}


56. Practical Cross-Browser Architecture

TestNG

   |

   v

Browser Configuration

   |

   +----------+----------+

   |          |          |

   v          v          v

Chrome     Firefox      Edge

Options    Options      Options

   |          |          |

   +----------+----------+

              |

              v

       RemoteWebDriver

              |

              v

       Selenium Grid

              |

      +-------+-------+

      |       |       |

    Node 1  Node 2  Node 3

      |       |       |

   Chrome  Firefox   Edge


57. Real-World E-Commerce Example

Consider an e-commerce application that needs to execute the same checkout test across multiple browsers.

Checkout Test

     |

     +---- Chrome ----> Grid Node 1

     |

     +---- Firefox ---> Grid Node 2

     |

     +---- Edge ------> Grid Node 3

Each test execution can create its own remote browser session while the same checkout test logic is reused.


58. Grid Architecture with Parallel Test Data

Grid becomes particularly useful when browser combinations and test data combinations are both involved.

Test Data

   |

   +---- User 1

   +---- User 2

   +---- User 3

   |

   v

TestNG DataProvider

   |

   +---- Chrome

   +---- Firefox

   +---- Edge

   |

   v

RemoteWebDriver

   |

   v

Selenium Grid

   |

   +---- Node 1

   +---- Node 2

   +---- Node 3

When designed correctly, this combination can provide broad test coverage while reducing overall execution time.


59. Troubleshooting Grid Architecture

Problem 1: Session Cannot Be Created

Possible causes include:

  • No suitable Node is available.
  • No compatible browser slot exists.
  • Browser capabilities do not match Node capabilities.
  • Node is unavailable.
  • Grid components are not communicating correctly.

Problem 2: Connection Refused

Check the Grid URL, port, network connectivity, and whether the Grid server is running.

Problem 3: Browser Does Not Start

Check browser installation, driver configuration, Node configuration, permissions, and available system resources.

Problem 4: Parallel Tests Interfere

Check whether WebDriver, test data, temporary files, or other mutable resources are incorrectly shared between threads.


60. Important Grid Components Quick Reference

ComponentRemember This
RouterFront door of the Grid and request router.
New Session QueueWaits for new session requests to be assigned.
DistributorFinds a matching Node and slot.
NodeRuns browser sessions.
SlotRepresents a place where a session can run.
Session MapMaps session IDs to Nodes.
Event BusProvides asynchronous communication.
RemoteWebDriverAllows the test to communicate with a remote browser.


61. Interview Questions on Grid Architecture

1. What is Selenium Grid?

Selenium Grid is a Selenium component used to execute WebDriver tests on remote machines and distribute browser sessions across available execution environments.

2. Why is Selenium Grid used?

It is commonly used for parallel execution, cross-browser testing, cross-platform testing, and remote browser execution.

3. What is a Node?

A Node is an execution endpoint that runs WebDriver browser sessions.

4. What is a Router?

The Router is the entry point that routes incoming WebDriver requests to the appropriate Grid component.

5. What is a Distributor?

The Distributor determines which Node and slot should receive a new session request.

6. What is a Session Map?

The Session Map maintains the relationship between a session ID and the Node running that session.

7. What is a New Session Queue?

It stores new session requests that are waiting to be assigned to an appropriate Node.

8. What is an Event Bus?

The Event Bus provides asynchronous communication between Grid components.

9. What is a Grid slot?

A slot represents a place on a Node where a WebDriver session can run.

10. What is RemoteWebDriver?

RemoteWebDriver is used to communicate with a browser running on a remote execution environment such as Selenium Grid.

11. Can Selenium Grid execute tests in parallel?

Yes. Grid can provide multiple browser sessions across available Nodes and slots, allowing independent tests to execute concurrently.

12. What is cross-browser testing?

Cross-browser testing means executing the same application tests against different browsers such as Chrome, Firefox, and Edge.

13. What is cross-platform testing?

Cross-platform testing means executing tests across different operating-system environments.

14. What is the difference between local WebDriver and RemoteWebDriver?

Local WebDriver normally starts a browser on the local machine, while RemoteWebDriver communicates with a remote browser execution environment.

15. How does Grid select a Node?

The Distributor evaluates available slots and matches the new session request against the capabilities supported by those slots.

16. Why is the Session Map required?

It helps Grid determine which Node owns a particular WebDriver session.

17. Why is the Event Bus used?

It allows Grid components to communicate asynchronously through events.

18. Can Selenium Grid be integrated with TestNG?

Yes. TestNG can manage test execution and parallelization while Selenium Grid provides remote browser execution.

19. Can Selenium Grid be used with Page Object Model?

Yes. Page Objects can interact with a WebDriver instance that happens to be a RemoteWebDriver connected to Grid.

20. What is the main advantage of distributed Grid architecture?

It allows Grid components and browser execution resources to be distributed across infrastructure, which can support larger and more scalable automation environments.


62. Quick Revision Notes

  • Selenium Grid: Remote and distributed browser execution infrastructure.
  • Router: Main request entry point.
  • New Session Queue: Holds pending new session requests.
  • Distributor: Assigns sessions to matching Nodes and slots.
  • Node: Runs browser sessions.
  • Slot: Execution location for a session.
  • Session Map: Maps sessions to Nodes.
  • Event Bus: Supports asynchronous Grid communication.
  • RemoteWebDriver: Connects test code to remote browser execution.
  • Parallel Execution: Multiple independent sessions can run concurrently.
  • Cross-Browser: Tests can run against multiple browser types.
  • Cross-Platform: Tests can run across different operating systems.
  • Scalability: Additional Nodes can provide additional execution capacity.


63. Learning Roadmap for Grid Architecture

  1. Understand Selenium WebDriver.
  2. Understand RemoteWebDriver.
  3. Learn the purpose of Selenium Grid.
  4. Understand Standalone mode.
  5. Understand Hub-Node architecture.
  6. Learn the Selenium Grid 4 components.
  7. Understand Router.
  8. Understand New Session Queue.
  9. Understand Distributor.
  10. Understand Node and Slot.
  11. Understand Session Map.
  12. Understand Event Bus.
  13. Learn capability matching.
  14. Practice RemoteWebDriver.
  15. Configure multiple browser Nodes.
  16. Practice parallel execution.
  17. Combine Grid with TestNG.
  18. Combine Grid with Page Object Model.
  19. Build a Driver Factory.
  20. Integrate Grid with CI/CD.
  21. Learn monitoring and troubleshooting.
  22. Practice distributed Grid architecture.


64. Practical Exercises

  1. Set up a basic Selenium Grid environment.
  2. Run a Chrome test through RemoteWebDriver.
  3. Run a Firefox test through RemoteWebDriver.
  4. Run an Edge test through RemoteWebDriver.
  5. Configure multiple Nodes.
  6. Execute the same test against multiple browsers.
  7. Create a TestNG DataProvider for browser names.
  8. Execute browser tests in parallel.
  9. Create a Driver Factory for Grid execution.
  10. Integrate Grid with Page Object Model.
  11. Run Grid tests from Maven.
  12. Integrate Grid execution into a CI/CD pipeline.
  13. Monitor Node availability and sessions.
  14. Practice troubleshooting session-creation failures.


65. Real-World Grid Architecture

                    CI/CD Pipeline

                          |

                          v

                    Test Framework

                          |

                 +--------+--------+

                 |                 |

               TestNG         DataProvider

                 |                 |

                 +--------+--------+

                          |

                    Driver Factory

                          |

                    RemoteWebDriver

                          |

                          v

                       Router

                          |

          +---------------+---------------+

          |               |               |

          v               v               v

    Session Queue    Session Map     Distributor

                                          |

                                      Event Bus

                                          |

                    +---------------------+---------------------+

                    |                     |                     |

                    v                     v                     v

                  Node 1                Node 2                Node 3

                    |                     |                     |

                  Chrome               Firefox                 Edge

                    |                     |                     |

                    +---------------------+---------------------+

                                          |

                                          v

                                     Application

                                          |

                                          v

                                      Assertions

                                          |

                                          v

                                       Reports


66. Summary

Selenium Grid Architecture provides the infrastructure required to execute Selenium WebDriver sessions remotely and distribute them across multiple browser environments.

The main Selenium Grid components include the Router, New Session Queue, Distributor, Node, Session Map, and Event Bus. The Router receives requests, the New Session Queue holds pending session requests, the Distributor selects suitable execution slots, Nodes run browser sessions, the Session Map tracks session ownership, and the Event Bus provides asynchronous communication between components.

Understanding Grid architecture is important for building scalable Selenium automation frameworks because it explains how a RemoteWebDriver request travels from the test framework to the actual browser session.

Grid can be combined with TestNG, Data Providers, Page Object Model, Driver Factory, Maven, CI/CD pipelines, and reporting systems to create maintainable and scalable automation infrastructure.


67. Course Resources

Learn more about Selenium WebDriver, Selenium Grid, automation testing, and related concepts:

Final Takeaway: Selenium Grid distributes WebDriver execution across browser Nodes and provides the architecture required for remote, parallel, cross-browser, and scalable Selenium automation. The key flow to remember is Client → Router → Session Queue → Distributor → Slot → Node → Browser, while the Session Map tracks running sessions and the Event Bus supports internal asynchronous communication.

whatsapp